﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using QLKS.Models;
using System.ComponentModel;

namespace QLKS.ViewModels
{
    public class SoDoPhongViewModel
    {
        ObservableCollection<TangViewModel> _dsTang;
        int _selectedTang = 0;

        public SoDoPhongViewModel()
        {
            _dsTang = new ObservableCollection<TangViewModel>();
            for (int i = 1; i <= PhongModel.GetSoLuongTang(); i++)
            {
                TangViewModel vm = new TangViewModel(i);
                vm.PropertyChanged += OnTangPropertyChanged;
                _dsTang.Add(vm);
            }
        }

        public ObservableCollection<TangViewModel> DsTang { get { return _dsTang; } }

        private void OnTangPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            string property = "IsSelected";
            TangViewModel vm = sender as TangViewModel;
            if (e.PropertyName == property)
            {
                if (_selectedTang != 0)
                    _dsTang[_selectedTang - 1].SelectedIndex = -1;
                _selectedTang = vm.Tang;
            }
        }
    }
}
